﻿/*
Typps HTML Editor for ASP.NET
FULL EDITION

Copyright (c) 2009 Alessandro Zifiglio, http://www.Typps.com
EMail: alessandro@Typps.com

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
Sys.Browser.WebKit = {}; //Safari 3 is considered WebKit
if (navigator.userAgent.indexOf('WebKit/') > -1) {
	Sys.Browser.agent = Sys.Browser.WebKit;
	Sys.Browser.version = parseFloat(navigator.userAgent.match(/WebKit\/(\d+(\.\d+)?)/)[1]);
	Sys.Browser.name = 'WebKit';
}

Type.registerNamespace("Typps");

Typps.EventArgs = function () {
	Typps.EventArgs.initializeBase(this);
	this._commandName = null;
	this._commandArgument = null;
	this._innerArgs = null;
}
Typps.EventArgs.prototype = {
	get_commandName: function () { return this._commandName; },
	set_commandName: function (value) { this._commandName = value; },
	get_commandArgument: function () { return this._commandArgument; },
	set_commandArgument: function (value) { this._commandArgument = value; },
	get_innerArgs: function () { return this._innerArgs; },
	set_innerArgs: function (value) { this._innerArgs = value; }
}
Typps.EventArgs.registerClass('Typps.EventArgs', Sys.EventArgs);

Typps.MediaItemEventArgs = function () {
	Typps.MediaItemEventArgs.initializeBase(this);
	this._sender = null;
	this._element = null;
	this._header = null;
	this._footer = null;
	this._oldWidth = null;
	this._oldHeight = null;
}
Typps.MediaItemEventArgs.prototype = {
	get_sender: function () { return this._sender; },
	set_sender: function (value) { this._sender = value; },
	get_element: function () { return this._element; },
	set_element: function (value) { this._element = value; },
	get_header: function () { return this._header; },
	set_header: function (value) { this._header = value; },
	get_footer: function () { return this._footer; },
	set_footer: function (value) { this._footer = value; },
	get_oldWidth: function () { return this._oldWidth; },
	set_oldWidth: function (value) { this._oldWidth = value; },
	get_oldHeight: function () { return this._oldHeight; },
	set_oldHeight: function (value) { this._oldHeight = value; }
}

Typps.MediaItemEventArgs.registerClass('Typps.MediaItemEventArgs', Sys.EventArgs);
Typps.Perform = function () { };
Typps.Perform.prototype =
{
	Add: 0,
	Remove: 1,
	Toggle: 2
}
Typps.Perform.registerEnum('Typps.Perform');
Typps.Utility = function () {
	//hr,br cannot contain child elements, so keep them in the list.
	this._blockElements = ['ol', 'p', 'pre', 'table', 'td', 'ul', 'blockquote', 'div', 'dl', 'fieldset', 'address', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'noscript', 'hr'];
	this._blockContentNodes = ['p', 'div', 'li', 'tr', 'td', 'pre', 'dl', 'dt', 'dd'];
}
Typps.Utility.getInstance = function Typps$Utility$getInstance() {
	var instance = Typps.Utility._instance;
	if (!instance) {
		instance = Typps.Utility._instance = new Typps.Utility();
	}
	return instance;
}
Typps.Utility.getBlockLevelElements = function Typps$Utility$getBlockLevelElements() {
	return Typps.Utility.getInstance()._blockElements;
}
Typps.Utility.getHighestZIndex = function Typps$Utility$getHighestZIndex() {
	var zIndex = Typps.Utility._zIndex;
	if (!zIndex) {
		zIndex = Typps.Utility._zIndex = Typps.Utility.getInstance()._getNextHighestZindex(null);
	}
	return zIndex;
}
Typps.Utility.isAlphaNumericValidate = function Typps$Utility$isAlphaNumericValidate(alphanumeric) {
	return Typps.Utility.getInstance()._isAlphaNumericValidate(alphanumeric);
}
Typps.Utility.regExpEscape = function Typps$Utility$regExpEscape(text) {
	return Typps.Utility.getInstance()._regExpEscape(text);
}
Typps.Utility.incrementZIndex = function Typps$Utility$incrementZIndex(i) {
	if (i == null || i < 0) i = 1;
	var zIndex = Typps.Utility._zIndex;
	if (zIndex)
		zIndex = Typps.Utility._zIndex = Typps.Utility._zIndex + i;
	else
		zIndex = Typps.Utility.getHighestZIndex(null);
	return zIndex;
}
Typps.Utility.paragraphWrap = function Typps$Utility$paragraphWrap(node, doc) {
	return Typps.Utility.getInstance()._paragraphWrap(node, doc);
}
Typps.Utility.isNbsp = function Typps$Utility$isNbsp(textNode) {
	return Typps.Utility.getInstance()._isNbsp(textNode);
}
Typps.Utility.getFormKeyValuePair = function Typps$Utility$(id, formKeyValuePair, form, includeAll) {
	return Typps.Utility.getInstance()._getFormKeyValuePair(id, formKeyValuePair, form, includeAll);
}
Typps.Utility.splitText = function Typps$Utility$(doc, node, offset) {
	return Typps.Utility.getInstance()._splitText(doc, node, offset);
}
Typps.Utility.getCommandArgument = function Typps$Utility$getCommandArgument(command, ae) {
	return Typps.Utility.getInstance()._getCommandArgument(command, ae);
}
Typps.Utility.windowBounds = function Typps$Utility$windowBounds() {
	return Typps.Utility.getInstance()._windowBounds();
}
Typps.Utility.scrollDistance = function Typps$Utility$scrollDistance(w) {
	return Typps.Utility.getInstance()._scrollDistance(w);
}
Typps.Utility.getScrollBarWidth = function Typps$Utility$getScrollBarWidth() {
	return Typps.Utility.getInstance()._getScrollBarWidth();
}
Typps.Utility.getParentOffset = function Typps$Utility$getParentOffset(elem) {
	return Typps.Utility.getInstance()._getParentOffset(elem);
}
Typps.Utility.getAdjacentHTML = function Typps$Utility$getAdjacentHTML(markup, container) {
	return Typps.Utility.getInstance()._getAdjacentHTML(markup, container);
}
Typps.Utility.getIndexByNameFromOptions = function Typps$Utility$getIndexByNameFromOptions(value, option) {
	return Typps.Utility.getInstance()._getIndexByNameFromOptions(value, option);
}
Typps.Utility.applyShade = function Typps$Utility$applyShade(element, shaderColor, transparency, zIndex) {
	return Typps.Utility.getInstance()._applyShade(element, shaderColor, transparency, zIndex);
}
Typps.Utility.setFloat = function Typps$Utility$setFloat(element, direction) {
	return Typps.Utility.getInstance()._setFloat(element, direction);
}
Typps.Utility.setTransparency = function Typps$Utility$setTransparency(element, val1) {
	return Typps.Utility.getInstance()._setTransparency(element, val1);
}
Typps.Utility.setBackGroundImage = function Typps$Utility$setBackGroundImage(element, imageUrl, repeat, position) {
	return Typps.Utility.getInstance()._setBackGroundImage(element, imageUrl, repeat, position);
}
Typps.Utility.isDesignMode = function Typps$Utility$isDesignMode(doc) {
	return Typps.Utility.getInstance()._isDesignMode(doc);
}
Typps.Utility.addScriptBlocks = function Typps$Utility$addScriptBlocks(id, evt, code) {
	return Typps.Utility.getInstance()._addScriptBlocks(id, evt, code);
}
Typps.Utility.setDesignMode = function Typps$Utility$setDesignMode(doc, value) {
	return Typps.Utility.getInstance()._setDesignMode(doc, value);
}
Typps.Utility.createBlockScreen = function Typps$Utility$createBlockScreen(id, shaderColor, shaderOpacity) {
	return Typps.Utility.getInstance()._createBlockScreen(id, shaderColor, shaderOpacity);
}
Typps.Utility.toggleBlockScreen = function Typps$Utility$toggleBlockScreen(elem, zIndex) {
	return Typps.Utility.getInstance()._toggleBlockScreen(elem, zIndex);
}
Typps.Utility.applyBlockScreenBounds = function Typps$Utility$applyBlockScreenBounds(id) {
	return Typps.Utility.getInstance()._applyBlockScreenBounds(id);
}
Typps.Utility.setLocation = function Typps$Utility$setLocation(elem) {
	return Typps.Utility.getInstance()._setLocation(elem);
}
Typps.Utility.getLocationByElement = function Typps$Utility$getLocationByElement(elem) {
	return Typps.Utility.getInstance()._getLocationByElement(elem);
}
Typps.Utility.getLocationBySize = function Typps$Utility$getLocationBySize(width, height) {
	return Typps.Utility.getInstance()._getLocationBySize(width, height);
}
Typps.Utility.toggleSelectElement = function Typps$Utility$toggleSelectElement(elem, selectCache) {
	return Typps.Utility.getInstance()._toggleSelectElement(elem, selectCache);
}
Typps.Utility.isNullOrEmpty = function Typps$Utility$isNullOrEmpty(value) {
	return Typps.Utility.getInstance()._isNullOrEmpty(value);
}
Typps.Utility.addRemoveClassName = function Typps$Utility$addRemoveClassName(elem, className, operation) {
	return Typps.Utility.getInstance()._addRemoveClassName(elem, className, operation);
}
Typps.Utility.containsCssClass = function Typps$Utility$addRemoveClassName(elem, className) {
	return Typps.Utility.getInstance()._containsCssClass(elem, className);
}
Typps.Utility.requiresParagraph = function Typps$Utility$requiresParagraph(node) {
	return Typps.Utility.getInstance()._requiresParagraph(node);
}
Typps.Utility.getTokenId = function Typps$Utility$getTokenId(doc) {
	return Typps.Utility.getInstance()._getTokenId(doc);
}
Typps.Utility.isEmptyTextNode = function Typps$Utility$isEmptyTextNode(node) {
	return Typps.Utility.getInstance()._isEmptyTextNode(node);
}
Typps.Utility.isBr = function Typps$Utility$isBr(node) {
	return Typps.Utility.getInstance()._isBr(node);
}
Typps.Utility.isElementNode = function Typps$Utility$isElementNode(node) {
	return Typps.Utility.getInstance()._isElementNode(node);
}
Typps.Utility.insertAfter = function Typps$Utility$insertAfter(newNode, node) {
	return Typps.Utility.getInstance()._insertAfter(newNode, node);
}
Typps.Utility.getForm = function Typps$Utility$getForm(id) {
	return Typps.Utility.getInstance()._getForm(id);
}
Typps.Utility.prototype = {
	_requiresParagraph: function (node) {
		//nodeType 1 = Element node
		if (node.nodeType != 1 || this._isEmptyTextNode(node) ||
            this._isNbsp(node))
			return true;
		var nodeName = node.nodeName.toLowerCase();
		switch (nodeName) {
			case 'br':
			case 'hr':
				return false;
		}
		for (var num1 = 0; num1 < this._blockContentNodes.length; num1++) {
			var match = this._blockContentNodes[num1];
			if (match == nodeName)
				return false;
		}
		return true;
	},
	_insertAfter: function (parent, node, referenceNode) {
		parent.insertBefore(node, referenceNode.nextSibling);
	},
	_paragraphWrap: function (node, doc) {
		if (this._isNestedInBlockElement(node) ||
            !this._requiresParagraph(node))
			return null;
		var container = doc.createElement('p');
		var newParagraph = doc.createElement('p');
		this._insertAfter(node.parentNode, container, node);
		while (node != null) {
			var currentNode = node;
			node = node.previousSibling;
			if (this._requiresParagraph(currentNode))
				container.insertBefore(currentNode.parentNode.removeChild(currentNode), container.firstChild);
			else
				break;
		}
		this._insertAfter(container.parentNode, newParagraph, container);
		var br = doc.createElement('br');
		newParagraph.appendChild(br);
		return br;
	},
	_isPreWrapped: function (textNode) {
		var parentNode = textNode.parentNode;
		while (parentNode) {
			if (parentNode.nodeName.toLowerCase() == 'pre')
				return true;
			parentNode = parentNode.parentNode;
		}
		return false;
	},
	_isNbsp: function (textNode) {
		if (textNode.nodeType != 3)
			return false;
		var pat = /\u00A0/;
		return textNode.nodeValue.match(pat);
	},
	_isNestedInBlockElement: function (element) {
		for (var num1 = 0; num1 < this._blockContentNodes.length; num1++) {
			var tagName = this._blockContentNodes[num1];
			while (element.nodeName.toLowerCase() != tagName) {
				element = element.parentNode;
				if (element == null || element.nodeName.toLowerCase() == 'body')
					return false;
			}
			if (element.nodeName.toLowerCase() == tagName)
				break;
		}
		return true;
	},
	_getFormKeyValuePair: function (id, formKeyValuePair, form, includeAll) {
		var formBody = new Sys.StringBuilder();
		for (var s in formKeyValuePair) {
			if (s != 'formdata')
				formBody.append(String.format('{0}={1}&', s, encodeURIComponent(formKeyValuePair[s])));
			else
				formBody.append(String.format('{0}${1}={2}&', s, id, encodeURIComponent(formKeyValuePair[s])));
		}
		formBody.append(String.format('iscallback${0}=true&', id));
		formBody.append('iscallback$Typps=true&');
		if (includeAll) {
			var count = form.elements.length;
			for (var i = 0; i < count; i++) {
				var element = form.elements[i];
				var name = element.name;
				if (typeof (name) === "undefined" || (name === null) || (name.length === 0)) {
					continue;
				}
				var tagName = element.tagName;
				if (tagName === 'INPUT') {
					var type = element.type;
					if ((type === 'text') ||
                        (type === 'password') ||
                        (type === 'hidden') ||
                        (((type === 'checkbox') || (type === 'radio')) && element.checked)) {
						formBody.append(encodeURIComponent(name));
						formBody.append('=');
						formBody.append(encodeURIComponent(element.value));
						formBody.append('&');
					}
				}
				else if (tagName === 'SELECT') {
					var optionCount = element.options.length;
					for (var j = 0; j < optionCount; j++) {
						var option = element.options[j];
						if (option.selected) {
							formBody.append(encodeURIComponent(name));
							formBody.append('=');
							formBody.append(encodeURIComponent(option.value));
							formBody.append('&');
						}
					}
				}
				else if (tagName === 'TEXTAREA') {
					formBody.append(encodeURIComponent(name));
					formBody.append('=');
					formBody.append(encodeURIComponent(element.value));
					formBody.append('&');
				}
			}
		}
		return formBody.toString();
	},
	_getCommandArgument: function (commandName, callbacks) {
		for (var index in callbacks) {
			var c = callbacks[index];
			if (c.commandName == commandName)
				return c;
		}
		return { message: null, commandArgument: null };
	},
	_windowBounds: function (w) {
		if (w == null)
			w = window;
		var inner = { x: 0, y: 0 };
		var outer = { x: 0, y: 0 };
		var doc = w.document;
		if (w.innerHeight) {
			inner.x = w.innerWidth;
			inner.y = w.innerHeight;
			outer.x = w.outerWidth;
			outer.y = w.outerHeight;
		}
		else if (doc.documentElement && doc.documentElement.clientHeight) {
			// Explorer 6 Strict Mode
			inner.x = doc.documentElement.clientWidth;
			inner.y = doc.documentElement.clientHeight;
			outer.x = doc.documentElement.scrollWidth;
			outer.y = doc.documentElement.scrollHeight;
		}
		else if (doc.body) {
			// other Explorers
			inner.x = doc.body.clientWidth;
			inner.y = doc.body.clientHeight;
			outer.x = doc.body.scrollWidth;
			outer.y = doc.body.scrollHeight;
		}
		return { ix: inner.x, iy: inner.y, ox: outer.x, oy: outer.y };
	},
	_scrollDistance: function (w) {
		if (w == null)
			w = window;
		var scroll = { x: 0, y: 0 };
		var doc = w.document;
		// all except Explorer
		if (w.pageYOffset ||
		    w.pageXOffset) {
			scroll.x = w.scrollX;
			scroll.y = w.scrollY;
		}
		else if (doc.documentElement && (doc.documentElement.scrollTop ||
		        doc.documentElement.scrollLeft)) {
			// Explorer 6 Strict
			scroll.x = doc.documentElement.scrollLeft;
			scroll.y = doc.documentElement.scrollTop;
		}
		// all other Explorers
		else if (doc.body) {
			scroll.x = doc.body.scrollLeft;
			scroll.y = doc.body.scrollTop;
		}
		return scroll;
	},
	_getScrollBarWidth: function () {
		var container = document.createElement('div');
		container.style.position = 'absolute';
		container.style.top = '-1000px';
		container.style.left = '-1000px';
		container.style.width = '100px';
		container.style.height = '50px';
		container.style.overflow = 'hidden';

		var content = document.createElement('div');
		content.style.width = '100%';
		content.style.height = '200px';
		container.appendChild(content);
		document.body.appendChild(container);

		var contentWidth = content.offsetWidth;
		container.style.overflow = 'auto';
		var containerWidth = content.offsetWidth;
		container.parentNode.removeChild(container);

		return (contentWidth - containerWidth);
	},
	_getParentOffset: function (elem) {
		var position = { x: 0, y: 0 }, offsetParent;
		do {
			position.x += elem.offsetLeft;
			position.y += elem.offsetTop;
			offsetParent = elem.offsetParent;
			if (offsetParent && (offsetParent.style.left != 0 || offsetParent.style.top != 0)) {
				break;
			}
		} while (elem = offsetParent);
		return position;
	},
	_getAdjacentHTML: function (markup, container) {
		if (container.insertAdjacentHTML) { // IE and opera
			container.insertAdjacentHTML('beforeEnd', markup);
		}
		else if (container.ownerDocument.createRange) { // all others, opera included.
			var range = container.ownerDocument.createRange();
			range.selectNodeContents(container);
			range.deleteContents();
			if (range.createContextualFragment) { // exclude opera, since it does not support it :-)
				var documentFragment = range.createContextualFragment(markup);
				container.appendChild(documentFragment);
			}
		}
		return container;
	},
	_getIndexByNameFromOptions: function (value, options) {
		for (var num1 = 0; num1 < options.length; num1++) {
			var option = options[num1];
			if (option.value.toLowerCase() == value.toLowerCase())
				return num1;
		}
		return -1;
	},
	_applyShade: function (element, shaderColor, transparency, zIndex) {
		var bounds = this.windowBounds();
		element.style.width = bounds.ix + 'px';
		element.style.height = bounds.iy + 'px';
		element.style.zIndex = zIndex; // pick a random high zindex
		Sys.UI.DomElement.setLocation(element, 0, 0);
		element.style.backgroundColor = shaderColor;
		this.setTransparency(element, transparency);
	},
	_setFloat: function (element, direction) {
		if (element == null) return;
		if (Sys.Browser.agent == Sys.Browser.InternetExplorer)
			element.style.styleFloat = direction;
		else
			element.style.cssFloat = direction;
	},
	_setTransparency: function (element, val1) {
		///val1 is transparency value as supported by IE, for non IE divide by 100
		var val2 = val1 / 100;
		if (Sys.Browser.agent == Sys.Browser.InternetExplorer) {
			if (val1 == 100)
				element.style.filter = '';
			else
				element.style.filter += String.format('progid:DXImageTransform.Microsoft.Alpha(Opacity={0})', val1);
		}
		else {
			element.style.opacity = val2;
		}
	},
	_setBackGroundImage: function (element, imageUrl, repeat, position) {
		element.style.backgroundRepeat = repeat;
		element.style.backgroundPosition = position;
		element.style.backgroundImage = String.format("url({0})", imageUrl);
	},
	_isDesignMode: function (doc) {
		var returnValue = false;
		var designMode = doc.designMode.toLowerCase();
		if (designMode == 'on')
			returnValue = true;
		if (Sys.Browser.agent == Sys.Browser.InternetExplorer) {
			if (doc.body != null && doc.body.contentEditable == 'true')
				returnValue = true;
		}
		return returnValue;
	},
	_setDesignMode: function (doc, value) {/*use contentEditable for ie, works better with dynamic css contained in the object tag*/
		if (Sys.Browser.agent == Sys.Browser.InternetExplorer)
			doc.body.contentEditable = value;
		else
			doc.designMode = (value == true) ? 'on' : 'off';
	},
	_addScriptBlocks: function (id, evt, code) {
		var scriptclick = document.createElement('script');
		scriptclick.htmlFor = id;
		scriptclick.setAttribute('type', 'text/javascript');
		scriptclick.event = 'on' + evt;
		scriptclick.text = code;
		document.getElementsByTagName('head')[0].appendChild(scriptclick);
	},
	_getNextHighestZindex: function (obj) {
		var highestIndex = 0;
		var currentIndex = 0;
		var elArray = Array();
		if (obj) { elArray = obj.getElementsByTagName('*'); } else { elArray = document.getElementsByTagName('*'); }
		for (var i = 0; i < elArray.length; i++) {
			if (elArray[i].currentStyle) {
				currentIndex = parseFloat(elArray[i].currentStyle['zIndex']);
			} else if (window.getComputedStyle) {
				currentIndex = parseFloat(document.defaultView.getComputedStyle(elArray[i], null).getPropertyValue('z-index'));
			}
			if (!isNaN(currentIndex) && currentIndex > highestIndex) { highestIndex = currentIndex; }
		}
		return (highestIndex + 1);
	},
	_isAlphaNumericValidate: function (alphanumeric) {
		var regex = /^[0-9a-zA-Z\s]+$/;
		return regex.test(alphanumeric);
	},
	_regExpEscape: function (text) {
		return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
	},
	_createBlockScreen: function (id, shaderColor, shaderOpacity) {
		var shadeElement = $get(id);
		if (shadeElement == null) {
			shadeElement = document.createElement('div');
			shadeElement.id = id;
			shadeElement.style.backgroundColor = shaderColor;
			shadeElement.style.position = 'absolute';
			shadeElement.style.left = '0px';
			shadeElement.style.top = '0px';
			this._setTransparency(shadeElement, shaderOpacity);
			var container = document.body;
			if ((Sys.Browser.agent == Sys.Browser.InternetExplorer &&
                            Sys.Browser.version == 6) && document.forms.length > 0)
				container = document.forms[0];
			container.appendChild(shadeElement);
			shadeElement.style.display = 'none';
		}
		this._applyBlockScreenBounds(id);
		return shadeElement;
	},
	_toggleBlockScreen: function (elem, zIndex) {
		if (elem == null) return;
		elem.style.zIndex = zIndex;
		if (elem.style.display == '')
			elem.style.display = 'none';
		else
			elem.style.display = '';
	},
	_applyBlockScreenBounds: function (id) {
		var elem = $get(id);
		if (elem == null) return;
		var bounds = this._windowBounds();
		var distance = this._scrollDistance();
		var x = bounds.ix;
		var y = bounds.iy;
		var barWidth = 0;
		if (Sys.Browser.agent != Sys.Browser.InternetExplorer)
			barWidth = this._getScrollBarWidth();
		var html = document.getElementsByTagName('html')[0];
		if (html.scrollHeight > y && barWidth > 0)
			x -= barWidth;
		elem.style.width = x + distance.x + 'px';
		elem.style.height = y + distance.y + 'px';
	},
	_setLocation: function (elem) {
		if (elem == null) return;
		var location = Typps.Utility.getLocationByElement(elem);
		elem.style.left = location.x + 'px';
		elem.style.top = location.y + 'px';
	},
	_getLocationByElement: function (elem) {
		if (elem == null) return;
		return this._getLocationBySize(elem.offsetWidth, elem.offsetHeight);
	},
	_getLocationBySize: function (width, height) {
		var bounds = this._windowBounds();
		var distance = this._scrollDistance();
		var barWidth = 0;
		if (Sys.Browser.agent != Sys.Browser.InternetExplorer)
			barWidth = this._getScrollBarWidth();
		var x = bounds.ix;
		var y = bounds.iy;
		var html = document.getElementsByTagName('html')[0];
		if (html.scrollHeight > y && barWidth > 0)
			x -= barWidth;
		x = Math.round((x - width) / 2);
		y = Math.round((y - height) / 2);
		return { x: (x + distance.x), y: (y + distance.y) };
	},
	_toggleSelectElement: function (elem, selectsCache) {
		if (Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version <= 7) {
			var selects = document.getElementsByTagName('SELECT');
			//not all the selects! We want to ignore the ones in this popup
			var selectsToIgnore = elem.getElementsByTagName('SELECT');
			var sel = null;

			if (selectsCache == null) {
				for (var num1 = 0; num1 < selects.length; num1++) {
					sel = selects[num1];
					var skip = false;
					if (selectsToIgnore.length > 0) {
						for (var num2 = 0; num2 < selectsToIgnore.length; num2++) {
							if (sel == selectsToIgnore[num2]) {
								skip = true;
								break;
							}
						}
					}
					if (skip == true) continue;
					if (sel.style.display != 'none') {
						sel.style.display = 'none';
						if (selectsCache == null)
							selectsCache = new Array();
						selectsCache[selectsCache.length] = sel;
					}
				}
			}
			else {
				var length = selectsCache.length;
				for (var num3 = 0; num3 < length; num3++) {
					sel = selectsCache.pop();
					sel.style.display = '';
				}
				selectsCache = null;
			}
		}
		return selectsCache;
	},
	_isNullOrEmpty: function (value) {
		var isNullOrEmpty = true;
		if (value) {
			if (typeof (value) == 'string') {
				if (value.length > 0)
					isNullOrEmpty = false;
			}
		}
		return isNullOrEmpty;
	},
	_addRemoveClassName: function (elem, className, operation) {
		var add = operation == Typps.Perform.Add;
		var remove = operation == Typps.Perform.Remove;
		var toggle = operation == Typps.Perform.Toggle;
		var containsCssClass = this._containsCssClass(elem, className);
		if (!containsCssClass && remove) return;
		if (containsCssClass && add) return;

		var namesList = className.split(' ');
		if (namesList.length > 0) {
			for (var index in namesList) {
				var cn = namesList[index];
				if (cn != '') {
					var containsClass = Sys.UI.DomElement.containsCssClass(elem, cn);
					if (add) {
						if (!containsClass)
							Sys.UI.DomElement.addCssClass(elem, cn);
					} else if (remove) {
						if (containsClass)
							Sys.UI.DomElement.removeCssClass(elem, cn);
					} else if (toggle) {
						if (containsCssClass)
							Sys.UI.DomElement.removeCssClass(elem, cn);
						else
							Sys.UI.DomElement.addCssClass(elem, cn);
					}
				}
			}
		}
		if (elem.className == '') {
			if (this._isIE)
				elem.removeAttribute('className');
			else
				elem.removeAttribute('class');
		}
	},
	_containsCssClass: function (elem, className) {
		var namesList = className.split(' ');
		var returnValue = false;
		if (namesList.length > 0) {
			for (var index in namesList) {
				var cn = namesList[index];
				if (cn != '') {
					var containsClass = Sys.UI.DomElement.containsCssClass(elem, cn);
					//match all classes in list
					if (containsClass)
						returnValue = true;
					else
						returnValue = false;
				}
			}
		}
		return returnValue;
	},
	_getTokenId: function (doc) {
		var tokenId = 'token';
		var tokenIndex = 0;
		while ($get(String.format('{0}{1}', tokenId, tokenIndex), doc)) {
			tokenIndex++;
		}
		return tokenId += tokenIndex;
	},
	_isEmptyTextNode: function (node) {
		if (node != null && (node.nodeType == 3 && node.data.trim() == ''))
			return true;
		return false;
	},
	_isBr: function (node) {
		if (node != null && (node.nodeType == 1 && node.nodeName.toLowerCase() == 'br'))
			return true;
		return false;
	},
	_isElementNode: function (node) {
		if (node != null && (node.nodeType == 1)) return true;
		return false;
	},
	_insertAfter: function (newNode, node) {
		if (!node.nextSibling)
			node.parentNode.appendChild(newNode);
		else
			node.parentNode.insertBefore(newNode, node.nextSibling);
	},
	_getForm: function (id) {
		var form = null;
		if (!Typps.Utility.isNullOrEmpty(id))
			form = $get(id);
		if (!form)
			form = document.forms[0];
		return form;
	},
	_splitText: function (doc, node, offset) {
		if (node.nodeType != 3) return;
		var nextSibling, newTextNode;
		if (node.length == offset) {
			nextSibling = node.nextSibling;
			newTextNode = doc.createTextNode('');
			if (nextSibling == null) {
				node.parentNode.appendChild(newTextNode);
			} else {
				node.parentNode.insertBefore(newTextNode, nextSibling);
			}
		}
		else {
			return node.splitText(offset);
		}
		return newTextNode;
	}
}
Typps.Utility.registerClass('Typps.Utility');
// Since this script is not loaded by System.Web.Handlers.ScriptResourceHandler
// invoke Sys.Application.notifyScriptLoaded to notify ScriptManager 
// that this is the end of the script.
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded(); 
